import json

import requests
import random
# requested_urls = set()
# urls = [f'https://httpbin.org/get?value={random.randint(1,10)}' for i in range(10)]
# for url in urls:
#     if url not in requested_urls:
#         res = requests.get(url)
#         print(res.json())
#         requested_urls.add(url)
#     else:
#         print('该地址已经访问过了')


# 因为在发起post请求的时候  data={}是一个字典  集合中不能放字典对象所以要用MD5加密
import hashlib
requested_data = set()
url = 'https://httpbin.org/post'
datas = [{'id':101,'value':random.randint( 1,10) }  for i in range(1,10) ]
for data in datas:
    data_has = hashlib.md5(json.dumps(data).encode('utf-8')).hexdigest()
    if data_has not in requested_data:
        res = requests.post(url,data=data)
        requested_data.add(data_has)
        print(res.json())
    else:
        print('已经访问过了')

